<?php
class NavAction extends Action {
    private $brand = null;
    private $price = null;
    public function __construct() {
        parent::__construct();
        $this->brand = new BrandModel();
        $this->price = new PriceModel();
    }
    public function index() {
        parent::page();
        if(isset($_GET['sid'])) {
            $this->tpl->assign('oneNav',$this->model->findOne());
        }
        $this->tpl->assign('allNav',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.'nav/show.html');
    }
    public function add() {
        if(isset($_POST['send'])) $this->model->add() ? $this->redirect->succ('?a=nav','导航新增成功!') : $this->redirect->error('系统出错，导航新增失败!');
        if(isset($_GET['sid'])) {
            $allBrand = Tool::setObjectArray($this->brand->findNavBrand(),'id','name');
            $this->tpl->assign('allBrand',$allBrand);
            $this->tpl->assign('fNav',$this->model->findFatherNav());
        }
        $this->tpl->assign('allPrice',$this->price->findAddPrice());
        $this->tpl->display(SMARTY_ADMIN.'nav/add.html');
    }
    public function update() {
        if(isset($_GET['id'])) {
            $this->tpl->assign('selectedBrand',$this->model->findGoodsBrand());
            $this->tpl->assign('selectedPrice',$this->model->findGoodsPrice());
            $this->tpl->assign('allPrice',$this->price->findAddPrice());
            $this->tpl->assign('allBrand',Tool::setObjectArray($this->brand->findNavBrand(),'id','name'));
            $this->tpl->assign('oneNav',$this->model->findOne());
        }
        if(isset($_POST['send'])) $this->model->update() ? $this->redirect->succ(Tool::getPrevPage(),'导航修改成功!') : $this->redirect->error('系统出错，导航修改失败!');
        $this->tpl->display(SMARTY_ADMIN.'nav/update.html');
    }
    public function delete() {
        if(isset($_GET['id'])) $this->model->delete() ? $this->redirect->succ(Tool::getPrevPage(),'导航删除成功!') : $this->redirect->error('系统出错，导航删除失败!');
    }
    public function sort() {
        if($_POST['send']) $this->model->sort() ? $this->redirect->succ(Tool::getPrevPage()) : $this->redirect->error('系统出错，排序失败!');
    }
    public function checkNavName() {
        $this->model->checkNavName();
    }
}


?>